//
//  ModuleAViewController.swift
//  ModuleA
//
//  Created by zhanwenyan on 2018/10/17.
//  Copyright © 2018年 Newcoretech. All rights reserved.
//

import UIKit

class ModuleAViewController: UIViewController, NCModuleRouterController {
    
    var onResult: (([String : Any]?) -> Void)?
    var isPresent: Bool = false
    var name: String?
    var info: Int?
    
    static func `init`(params: [String : Any]?, onResult: (([String : Any]?) -> Void)?, isPresent: Bool) -> UIViewController? {
        let vc = ModuleAViewController()
        vc.name = params?["name"] as? String
        vc.info = params?["info"] as? Int
        vc.isPresent = isPresent
        vc.onResult = onResult
        return vc
    }

    @IBOutlet weak var paramLb: UILabel!
    @IBOutlet weak var resultTf: UITextField!
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "ModuleA"
        paramLb.text = "name=\(name ?? "");  info=\(info ?? 0)"
    }

    @IBAction func didSave(_ sender: Any) {
        let res = ["result": resultTf?.text ?? ""]
        onResult?(res)
        if(isPresent) {
            dismiss(animated: true, completion: nil)
        } else {
            navigationController?.popViewController(animated: true)
        }
    }
}
